<template>
	<view class="bindEntre">
		<navBar backColor="#000" background="#fff"></navBar>
		<h2>是否绑定该分销商？</h2>
		<view class="entreInfo">
			<image :src="followInfo.headimg" mode=""></image>
			{{followInfo.realname}}
		</view>
		<view class="subBtn">
			<button type="default" @click="toSubmit">确定</button>
		</view>
	</view>
</template>

<script>
	import navBar from '@/components/navBar/navBar.vue'
	import service_distri from '@/service/distri.js'
	import service_enter from '@/service/enter.js'
	export default{
		data(){
			return{
				follow_id:null,
				followInfo:{},
				newInfo:{},
				type:null,
				msg:'',
				enterType:null,
				enterStatus:null,
				enterReason:''
			}
		},
		components:{
			navBar
		},
		onLoad(options) {
			let scene= decodeURIComponent(options.scene) //二维码扫码时的参数
			console.log(scene,'二维码参数')
			console.log(options,'转发时参数')
			scene = scene.split("&");
			let obj = {}
			let app = getApp()
			for(let i = 0;i<scene.length;i++){
				let newscene = scene[i].split("=");
				obj[newscene[0]] = newscene[1];
			}
			if(obj.follow_id){
				this.follow_id = obj.follow_id
			}else {
				this.follow_id = options.follow_id
			}
			let token = this.$store.state.index.token
			if(!token){
				uni.setStorageSync('follow_id',this.follow_id);
				uni.redirectTo({
					url:'/pages_login/pages/login/login/index'
				})
			}else{
				uni.setStorageSync('follow_id',this.follow_id);
				this.getUserInfo()
			}
		},
		onShow() {
			let token = this.$store.state.index.token
			if(token){
				this.getEnterStatus()
			}
		},
		methods:{
			// 获取入驻状态
			getEnterStatus(){
				let user_id = this.$store.state.index.userId
				service_enter.getEnterStatus({user_id}).then(res=>{
					console.log(res,'入驻状态')
					if(res.code==1){
						this.enterStatus = res.data.status
						this.enterType = res.data.type
						this.enterReason = res.data.reason
					}
				})
			},
			// 获取用户创客状态
			getUserInfo(){
				let new_id = this.$store.state.index.userId
				let params = {
					follow_id:this.follow_id,
					new_id
				}
				service_distri.promoStatus(params).then(res=>{
					console.log(res)
					if(res.code==1){
						this.followInfo = res.data.follow_info;
						this.newInfo = res.data.new_info;
						this.type = res.data.type;
						this.msg = res.data.msg;
					}
				})
			},
			
			// 确定按钮
			toSubmit(){
				// uni.redirectTo({
				// 	url:'./applyData'
				// })
				if(this.enterType==0 && this.type==1){ //无入驻状态的新用户
					uni.navigateTo({
						url:`./applyData?follow_id=${this.follow_id}`
					})
				}else if(this.enterType!=2 && this.type==2){ //已入驻但未绑定创业主的自由精英
					let new_id = this.$store.state.index.userId
					let params = {
						follow_id:this.follow_id,
						new_id
					}
					service_distri.toFreeBecome(params).then(res=>{
						if(res.code==1){
							uni.redirectTo({
								url:'./success'
							})
						}
					})
				}else{ //申请状态
					if(this.enterStatus==0){
						if(this.enterType==2){
							console.log('申请中')
							uni.navigateTo({ 
								url: "/pages/enter/index/audit" ,
							})
						}
					}else if(this.enterStatus == 1){
						if(this.type!=1 && this.type!=2){
							uni.showToast({
								title:this.msg,
								icon:'none'
							})
						}else{
							uni.showToast({
								title:'申请已通过',
								icon:'success'
							})
						}
						setTimeout(function(){
							uni.reLaunch({
								url:'/pages/mall/newIndex/newIndex'
							})
						},1000)
					}else if(this.enterStatus == 2){
						uni.navigateTo({ url: "/pages/enter/index/fail?reason=" + this.enterReason })
					}
				}
			}
		}
	}
</script>

<style lang="scss" >
	page{height: 100%;}
	.bindEntre{
		width: 100%;
		height: 100%;
		background-color: #fff;
		h2{
			width: 100%;
			text-align: center;
			font: 500 40rpx/52rpx PingFang SC;
			margin: 60rpx 0 92rpx 0;
			color: #0A0605;
		}
		.entreInfo{
			margin: 0 auto;
			width: 568rpx;
			height: 316rpx;
			box-shadow:0rpx 0rpx 20rpx 1rpx rgba(0,0,0,0.1);
			display: flex;
			flex-direction: column;
			font: 400 26rpx/40rpx PingFang SC;
			color: #505050;
			align-items: center;
			justify-content: center;
			image{width: 120rpx;height: 120rpx;border-radius: 50%;}
			
		}
		.subBtn{
			width: 100%;
			text-align: center;
			position: fixed;
			bottom: 0;
			height: calc(94rpx+ constant(safe-area-inset-bottom));///兼容 IOS<11.2/
			height: calc(94rpx + env(safe-area-inset-bottom));///兼容 IOS>11.2/
			padding-bottom: constant(safe-area-inset-bottom);///兼容 IOS<11.2/
			padding-bottom: env(safe-area-inset-bottom);///兼容 IOS>11.2/
			button{
				// margin-bottom: 10rpx;
				width: 686rpx;
				height: 84rpx;
				background-color: #364052;
				color: #fff;
				font: 500 28rpx/84rpx PingFang SC;
				border-radius: 44rpx;
			}
		}
		
	}
</style>
